<?php
ob_start();
session_start();
include "checksession.php";
$id_member = $_SESSION["id_member"];

//$exeProde = "SELECT * FROM `product_detail` WHERE pd_status = 'NoUse'";
//$objQuery = mysql_query($exeProde);
//$objResult = mysql_fetch_array($objQuery);


?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
          <!--<script src="http://code.jquery.com/jquery-latest.js"></script>-->
        <link rel="stylesheet" href="../css/style.css"/>
        <!--         <link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css" />
               <script type="text/javascript" src="../js/jquery/jquery.js"></script>    
        <script type="text/javascript" src="../js/jquery/jquery.validationEngine.js"></script>-->
        <script type="text/javascript" src="../js/jquery/jquery-latest.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {

                $("#emp_id").change(function() {
                    $.ajax({
                        url: "returnAddListCom.php",
                        type: "POST",
                        data: 'semp_id=' + $("#emp_id").val()
                    })
                            .success(function(result) {

                        var obj = jQuery.parseJSON(result);

                        if (obj == '')
                        {
//                            $('input[type=text]').val('');
                            alert("ไม่พบพนักงานในระบบ");
                        }
                        else
                        {
                            $.each(obj, function(key, inval) {

                                $("#emp_id").val(inval["emp_id"]);
                                $("#cn_department").val(inval["departname"]);
                                $("#c_nameUser").val(inval["emp_nameEng"]);
                                $("#hid_department").val(inval["id"]);
                            });
                        }
                    });
                });
            });
        </script>
        <script type="text/javascript">
            $(document).ready(function() {

                $("#cn_number").change(function() {
                    $.ajax({
                        url: "returnAddListComName.php",
                        type: "POST",
                        data: 'scn_number=' + $("#cn_number").val()
                    })
                            .success(function(result) {

                        var obj = jQuery.parseJSON(result);

                        if (obj == '')
                        {
//                            $('input[type=text]').val('');
                        }
                        else
                        {
                            $.each(obj, function(key, inval) {

                                $("#cnNumber").val(inval["cn_number"]);
                                if (eval("document.frmMain.cnNumber.value") != "") {
                                    alert("หมายเลขเครื่องคอมพิวเตอร์ มีในระบบแล้ว");
                                    eval("document.frmMain.cnNumber.focus();")
                                    return false;
                                }

                            });
                        }
                    });
                });
            });
        </script>
        <script language="javascript">
            function CheckValidate()
            {
//                if (eval("document.frmMain.cn_number.value") == "") {
//                    alert("กรุณากรอกช่อง รหัสเครื่อง");
//                    eval("document.frmMain.cn_number.focus();")
//                    return false;
//                }

                if (eval("document.frmMain.cn_comeName.value") == "") {
                    alert("กรุณากรอกช่อง ชื่อเครื่อง");
                    eval("document.frmMain.cn_comeName.focus();")
                    return false;
                }

                if (eval("document.frmMain.emp_id.value") == "") {
                    alert("กรุณาเลือกช่อง รหัสพนักงาน");
                    eval("document.frmMain.emp_id.focus();")
                    return false;
                }

                if (eval("document.frmMain.cn_ip.value") == "") {
                    alert("กรุณากรอกช่อง IP Adress");
                    eval("document.frmMain.cn_ip.focus();")
                    return false;
                }

                if (eval("document.frmMain.c_mb.value") == "") {
                    alert("กรุณากรอกช่อง M/B Brand/Model");
                    eval("document.frmMain.c_mb.focus();")
                    return false;
                }

                if (eval("document.frmMain.c_vga.value") == "") {
                    alert("กรุณากรอกช่อง VGA Brand/Model");
                    eval("document.frmMain.c_vga.focus();")
                    return false;
                }

                if (eval("document.frmMain.c_cpu.value") == "") {
                    alert("กรุณากรอกช่อง CPU Brand/Model");
                    eval("document.frmMain.c_cpu.focus();")
                    return false;
                }

                if (eval("document.frmMain.c_ram.value") == "") {
                    alert("กรุณากรอกช่อง RAM Brand/Model");
                    eval("document.frmMain.c_ram.focus();")
                    return false;
                }

//                if (eval("document.frmMain.c_keyboard.value") == "") {
//                    alert("กรุณากรอกช่อง K/B Brand/Model");
//                    eval("document.frmMain.c_keyboard.focus();")
//                    return false;
//                }

                if (eval("document.frmMain.c_hdd.value") == "") {
                    alert("กรุณากรอกช่อง HDD Brand/Vol/Size");
                    eval("document.frmMain.c_hdd.focus();")
                    return false;
                }

//                if (eval("document.frmMain.c_mouse.value") == "") {
//                    alert("กรุณากรอกช่อง Mouse Brand/Model");
//                    eval("document.frmMain.c_mouse.focus();")
//                    return false;
//                }

                if (eval("document.frmMain.c_sound.value") == "") {
                    alert("กรุณากรอกช่อง  Sound Brand/Model");
                    eval("document.frmMain.c_sound.focus();")
                    return false;
                }

//                if (eval("document.frmMain.c_monitor.value") == "") {
//                    alert("กรุณากรอกช่อง Monitor Brand/Model");
//                    eval("document.frmMain.c_monitor.focus();")
//                    return false;
//                }

                if (eval("document.frmMain.c_cdRom.value") == "") {
                    alert("กรุณากรอกช่อง CD/ROM Brand/Model");
                    eval("document.frmMain.c_cdRom.focus();")
                    return false;
                }

                if (eval("document.frmMain.c_speaker.value") == "") {
                    alert("กรุณากรอกช่อง Speaker Brand");
                    eval("document.frmMain.c_speaker.focus();")
                    return false;
                }

                if (eval("document.frmMain.c_lan.value") == "") {
                    alert("กรุณากรอกช่อง Lan Card Brand/Model");
                    eval("document.frmMain.c_lan.focus();")
                    return false;
                }


            }
        </script>
    </head>
    <body>
        <div  align="center">
            <fieldset>
                <legend class="nameTitle">ลงทะเบียนประวัติคอมพิวเตอร์</legend>
                <form  
                    method="Post"
                    action="listCom_save.php"
                    name ="frmMain" id="frmMain" OnSubmit="return CheckValidate();" />
                <table class="inputcontenttable" ><br />
                    <tr align="top">
                        <td align="left">รหัสเครื่อง</td> 
                        <!--<td><input id="cn_number"  name="cn_number" type="text"/></td>-->
                        <td> 
                            <select name="cn_number" id="cn_number">	
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '7' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		
                                   
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                        <td width="50px"></td>
                        <td>ชื่อเครื่อง</td>
                        <td><input id="cn_comeName" name="cn_comeName" type="text"/></td>                      
                    </tr>
                    <tr valign="top" >
                        <td>รหัสพนักงาน</td>
                        <td><input id="emp_id" name="emp_id" type="text"/></td>      
                        <td width="50px"></td>
                        <td>IP Adress</td>
                        <td><input id="cn_ip" name="cn_ip" type="text"/></td>                          
                    </tr>
                    <tr valign="top" >

                    </tr>
                    <tr valign="top" >
                        <td>M/B Brand/Model</td>
                        <td><input id="c_mb" name="c_mb" type="text"/></td>   
                        <td width="50px"></td>
                        <td>VGA Brand/Model</td>
                        <td><input id="c_vga" name="c_vga" type="text"/></td>                          
                    </tr> 
                    <tr valign="top" >
                        <td>CPU Brand/Model</td>
                        <td><input id="c_cpu" name="c_cpu" type="text"/></td>    
                        <td width="50px"></td>
                        <td>FDD Brand/Model</td>
                        <td><input  name="c_fdd" type="text"/></td>                          
                    </tr>
                    <tr valign="top" >
                        <td>RAM Brand/Vol/Size</td>
                        <td><input id="c_ram" name="c_ram" type="text"/></td>        
                        <td width="50px"></td>
                        <td>K/B Brand/Model</td>
                        <!--<td><input  name="c_keyboard" type="text"/></td>-->    
                          <td> 
                            <select name="c_keyboard" id="c_keyboard">
                               <option value=""> NONE </option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '1' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                               
                                    <option value="<?= $objResuut["pd_id"]; ?>"><?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"];?></option>		
                                   
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr valign="top" >
                        <td>HDD Brand/Vol/Size</td>
                        <td><input  name="c_hdd" type="text"/></td>  
                        <td width="50px"></td>
                        <td>Mouse Brand/Model</td>
                        <!--<td><input  name="c_mouse" type="text" /></td>-->  
                          <td> 
                            <select name="c_mouse" id="c_mouse">	
                                <option value=""> NONE </option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '2' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"><?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		
                                   
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr valign="top" >
                        <td>Sound Brand/Model</td>
                        <td><input  name="c_sound" type="text"/></td>    
                        <td width="50px"></td>
                        <td>Monitor Brand/Model</td>
                        <!--<td><input name="c_monitor" type="text"/></td>-->  
                         <td> 
                            <select name="c_monitor" id="c_monitor">	
                                <option value=""> NONE </option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '3&4' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"><?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		                                 
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr valign="top" >
                        <td>CD/ROM Brand/Model</td>
                        <td><input  name="c_cdRom" type="text"/></td>  
                        <td width="50px"></td>
                        <td>Speaker Brand</td>
                        <td><input  name="c_speaker" type="text"/></td>                          
                    </tr>
                    <tr valign="top" >
                        <td>Lan Card Brand/Model</td>
                        <td><input  name="c_lan" type="text"/></td>    
                        <td width="50px"></td>
                        <td>Notice</td>
                        <td><input  name="c_notic" type="text" /></td>                          
                    </tr>
                    <tr valign="top" >
                        <td colspan="5" align="center">Other Device</td>                           
                    </tr>
                    <tr valign="top" >
                        <td>Device</td>
                        <td><input  name="oth_name" type="text" /></td>   
                        <td width="50px"></td>
                        <td>Case</td>
                       <td> 
                            <select name="oth_detail" id="oth_detail">	
                                <option value=""> NONE </option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '6' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		                                 
                                    <?
                                }
                                ?>
                            </select>
                        </td>                    
                    </tr>
                          <tr valign="top" >
                        <td>Device</td>
                        <td><input  name="oth_name2" type="text" /></td>   
                        <td width="50px"></td>
                        <td>UPS</td>
                       <td> 
                            <select name="oth_detail2" id="oth_detail2">	
                                <option value=""> NONE </option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '5' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		                                 
                                    <?
                                }
                                ?>
                            </select>
                        </td>                    
                    </tr>
                     <tr valign="top" >
                        <td>Device</td>
                        <td><input  name="oth_name3" type="text" /></td>   
                        <td width="50px"></td>
                        <td>Printer</td>
                       <td> 
                            <select name="oth_detail3" id="oth_detail3">	
                                <option value=""> NONE </option>
                                <?
                                include_once "../connect.php";
                                $strSQL = "SELECT  *  FROM product_detail LEFT  JOIN product ON product_detail.prd_id = product.prd_id WHERE pd_status = 'NoUse'  AND type_id	= '8' ORDER BY pd_id ASC";
                                $objQuery = mysql_query($strSQL);
                                while ($objResuut = mysql_fetch_array($objQuery)) {
                                    ?>
                                    <option value="<?= $objResuut["pd_id"]; ?>"> <?= $objResuut["pd_code"]; ?> <?= $objResuut["pd_name"]; ?></option>		                                 
                                    <?
                                }
                                ?>
                            </select>
                        </td>                    
                    </tr>
                    <tr valign="top" >                                  
                        <td>User</td>
                        <td><input id="c_nameUser"  name="c_nameUser" readonly /></td> 
                        <td width="50px"></td>
                        <td>แผนกฝ่าย</td>
                        <td><input  id="cn_department" name="cn_department" type="text" readonly/></td>  
                    </tr>
                    <tr>
                        <td colspan="5" align="center"><input align="center" type="submit" name="Submit" value="Save" style="height: 30px; width: 120px"/></td>
                    </tr>
                </table>
                <input type="hidden" name="cn_id"/>
                <input id="hid_department" type="hidden" name="hid_department"/>
                <input name="id_member" type="hidden" value="<?= $id_member ?>"/>
                <input type="hidden" name="cnNumber" id="cnNumber" />
                </form>
            </fieldset>
        </div>
    </body>
</html>
